package com.soft.javase.ch06.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/25
 */
public class SimpleDateFormatDemo {
    public static void main(String[] args) throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd");

        System.out.println("---------Date -> String----------");
        Date date1 = new Date();
        System.out.println("date1 = " + date1);
        String string1 = sdf.format(date1);
        String string3 = sdf1.format(date1);
        System.out.println("string1 = " + string1);
        System.out.println("string3 = " + string3);

        System.out.println("---------String -> Date----------");
        String string2 = "2021-10-26 09:52:55";
        String string4 = "2021/10/26";
        Date date2 = sdf.parse(string2);
        Date date3 = sdf1.parse(string4);
        System.out.println("date2 = " + date2);
        System.out.println("date3 = " + date3);

    }
}
